/**
 * Created by Admin on 2017/12/26.
 */
define(function (require, exports, module) {
    var commonPaging=require("../common/commonPagingCq");
    var tpl=require("./tpl/obligeeManageTpl.html");
    var myWidGet = require("../common/myWidGet");
    require("../common/serializeObject.js");
    require("../common/qy-template");
    require("../seajs-init");
    require("../common/dialog");

    var p;
    setTimeout(function(){
        p=new commonPaging({
            htmlContainer: "#Js_page_content",
            pageContainer: "#Js_fs_paging",
            url: window.jkconfig.webapiurlv+"applicantmanage/list",
            tpl:tpl,
            data:$("#searchForm").serialize()
        });
        p.init();
    },500)


    $(function() {
        var fatherBody = $(window.top.document.body);//找到父页面的body对象
        $("body").on("click",".btnSearch",function(){
            /*权利人、地址*/
            $("[name=applicantName]").val($.trim($("[name=applicantName]").val()));
            $("[name=address]").val($.trim($("[name=address]").val()));
            if($("#Js_fs_paging").css("display") == "block"){
                //p.page.destroy && p.page.destroy();
                $("[name=pageNumber]").val(1);
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: window.jkconfig.webapiurlv+"applicantmanage/list",
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            }else{
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: window.jkconfig.webapiurlv+"applicantmanage/list",
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            }
        }).on("click",".btnAreaClassify",function(){
            fatherBody.find("#modal-oArea").show();
        }).on("click",".btnIndustryClassify",function(){
            if($(".industryBox").find("span").length == 2) {
               alert("请添加行业!");
            }else{
                fatherBody.find("#modal-industry").show();
            }
        }).on("click",".btnMaintain",function(){
            fatherBody.find("#modal-editObligee").show();
            $.ajax({
                url:window.jkconfig.webapiurlv+"applicantmanage/info/"+$(this).attr("data-applicantId"),
                success:function(data){
                    fatherBody.find(".applicantName").html(data.info.applicantName);
                    fatherBody.find(".applicantName").attr("data-applicantId",data.info.applicantId);
                    fatherBody.find(".address").html(data.info.address);
                    fatherBody.find("#mainAreaId").val(data.info.areaId);
                    var industryIds = fatherBody.find("#modal-editObligee input[name=industryId]");
                    $.each(industryIds,function(index,element){
                        for(var i = 0;i<data.info.industryIds.length;i++){
                            if($(element).val() == data.info.industryIds[i]){
                                $(element).attr("checked",true);
                            }
                        }
                    })
                }
            })
        })
    })
})